package com.item.mofan.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.item.mofan.common.Result;
import com.item.mofan.entity.SetmealDish;
import com.item.mofan.entity.ShoppingCart;
import com.item.mofan.service.SetmealDishService;
import com.item.mofan.service.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;
    @Autowired
    private SetmealDishService setmealDishService;

    /**
     * 添加购物车
     * @param shoppingCart
     * @return
     */
    @PostMapping("/add")
    public Result<String> add(@RequestBody ShoppingCart shoppingCart){
        shoppingCartService.add(shoppingCart);
        return Result.success("添加成功");

    }
    /**
     * 展示购物车
     * @return
     */
    @GetMapping("/list")
    public Result<List<ShoppingCart>> list(){
        List<ShoppingCart> shoppingCarts = shoppingCartService.getList();
        return Result.success(shoppingCarts);
    }
    @PostMapping("/sub")
    public Result<String> delete(@RequestBody ShoppingCart shoppingCart){
        shoppingCartService.deleteCart(shoppingCart);
        return Result.success("已移出购物车");
    }
    @DeleteMapping("/clean")
    public Result<String> clean(){
        shoppingCartService.cleanCart();
        return Result.success("已清空购物车");
    }
}
